home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 98 / Skunkware 98.iso / osr5 / sco / scripts / admin / news / rcv_groups < prev    next >
Encoding:
Text File  |  1997-08-26  |  3.9 KB  |  133 lines

  1. :
  2. # @(#) rcv_groups.sh 1.0 93/04/29
  3. # 92/08/13 john h. dubois iii (john@armory.com)
  4. # 93/04/29 Print "Ignored" instead of "Bad"
  5. #          Require that article name *end* in a digit, not just include a digit
  6. #          Added d and p options
  7.  
  8. PathLen=2
  9. ReportDist=0
  10.  
  11. while getopts dhp:s: opt; do
  12.     case $opt in
  13.     h) echo \
  14. "Usage: $0 [-dh] [-p pathlen] [-s system] [-s system] ... [group ...]
  15. $0 determines what newsgroups the local system receives by scanning
  16. articles in the news tree.  Any group that has at least one article posted
  17. exclusively to it (not crossposted to any other groups) is reported as
  18. being received by the local system.  Articles which have only one system
  19. (generally the local system) listed on the Path: line are ignored.  
  20. Running diagnostics are written to stderr.  The list of newsgroups is
  21. written at completion to stdout.  The report can be restricted to
  22. particular groups by listing them after any options.
  23. Options:
  24. -d: For each newsgroup, print the greatest distance from which an article
  25.     was received (the highest number of systems on the Path: line).  This
  26.     scan takes much longer because every article must be examined.
  27. -h: Print this help.
  28. -s <system>: Restrict report to articles received from particular systems.
  29.    The system names must be the same as those added to the Path: line by
  30.    the systems.
  31. -p <pathlen>: Ignore articles that do not have at least <pathlen> systems
  32.    on the Path: line.  The default is 2.  A pathlen of 1 will include
  33.    articles posted locally.  A pathlen of e.g. 3 would be used when the
  34.    system's immediate newsfeed sends everything it receives to the local
  35.    system, but it does not receive everything; this ignores articles
  36.    generated on the immediate newsfeed."
  37.     exit;;
  38.     s) Systems="$Systems $OPTARG";;
  39.     p) PathLen=$OPTARG;;
  40.     d) ReportDist=1;;
  41.     esac
  42. done
  43.  
  44. let OPTIND=OPTIND-1
  45. shift $OPTIND
  46.  
  47. cd /usr/spool/news
  48.  
  49. if [ $# -gt 0 ]; then
  50.     for group in `echo $* | tr . /`; do
  51.     echo "$group"
  52.     done
  53. else
  54.     awk '{ gsub(/\./,"/",$1); print $1; }' /usr/lib/news/active
  55. fi | while read dir; do 
  56.     [ ! -d $dir ] && continue
  57.     for article in $dir/*
  58.     do
  59.     echo "$article"
  60.     done
  61. done |
  62. awk -v "PathLen=$PathLen" -v "ReportDist=$ReportDist" -v "SysList=$Systems" '
  63. BEGIN {
  64.     if (SysList == "")
  65.     AllGoodPath = 1
  66.     else {
  67.     split(SysList,F)
  68.     for (i in F)
  69.         Systems[F[i]]
  70.     }
  71. }
  72.  
  73. /\/[0-9]+$/ {
  74.     group = article = $0
  75.     sub("/[0-9]*$","",group)
  76.     gsub("/",".",group)
  77.     if (!ReportDist && (group in Distance)) {
  78.     printf "Skipping: %s   \015",article > "/dev/stderr"
  79.     next
  80.     }
  81.     Path = Newsgroups = ""
  82.     while (getline HeaderLine < article) {
  83.     if (HeaderLine == "")        # Found end of header
  84.         printf "Newsgroups or Path not found: %s    \015",article > \
  85.         "/dev/stderr"
  86.     else if (HeaderLine ~ "^Path:")
  87.         Path = HeaderLine
  88.     else if (HeaderLine ~ "^Newsgroups:")
  89.         Newsgroups = HeaderLine
  90.     if (Newsgroups != "" && Path != "") {
  91.         ProcHdr(Path,Newsgroups,group,article)
  92.         break
  93.     }
  94.     }
  95.     close(article)
  96. }
  97.  
  98. function ProcHdr(Path,Newsgroups,group,article,  Fields,NumSys) {
  99.     if (Newsgroups !~ "^Newsgroups: +"  group " *$") {
  100.     printf "Ignored: >1 newsgroup: %s         \015", article > "/dev/stderr"
  101.     return
  102.     }
  103.     if ((NumSys = split(Path,Fields,"!") - 1) < PathLen) {
  104.     printf "Ignored: Distance = %d: %s            \015",NumSys,
  105.     article > "/dev/stderr"
  106.     return
  107.     }
  108.     if (!AllGoodPath && !(Fields[2] in Systems)) {
  109.     printf "Ignored: not received from a specified system: %s        \015",
  110.     article > "/dev/stderr"
  111.     return
  112.     }
  113.     if (!(group in Distance))
  114.     print "\nGet group: " group > "/dev/stderr"
  115.     if (NumSys > Distance[group]) {
  116.     Distance[group] = NumSys
  117.     sub("^.*/","",article)
  118.     printf "%2d %s (%d)          \n",Distance[group],group,
  119.     article > "/dev/stderr"
  120.     }
  121. }
  122.  
  123. END {
  124.     print "" > "/dev/stderr"
  125.     if (ReportDist)
  126.     for (group in Distance)
  127.         printf "%2d %s\n",Distance[group],group
  128.     else
  129.     for (group in Distance)
  130.         print group
  131. }
  132. '
  133.